package com.jw.springframework.testbeanfactorypostprocessor;

import com.jw.springframework.testbeanfactorypostprocessor.beanfactorypostprocessor.AddByApplicationContextBeanDefinitionRegistryPostProcessor;
import com.jw.springframework.testbeanfactorypostprocessor.beanfactorypostprocessor.AddByApplicationContextBeanFactoryPostProcessor;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

/**
 * @ClassName: TestBeanFactoryPostProcessorMain
 * @Description: 测试beanFactoryPostProcessor的测试类
 * @Author: darkness
 * @Date: 2021/4/11 0011 22:15
 * @Version: 1.0
 * @Type: class
 **/
@ComponentScan("com.jw.springframework.testbeanfactorypostprocessor")
public class TestBeanFactoryPostProcessorMain {

    public static void main(String[] args) {
        AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext();
        /**
         * PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(beanFactory, getBeanFactoryPostProcessors());
         * 这个静态方法调用了getBeanFactoryPostProcessors()返回了applicationContext中的beanFactoryPostProcessors(List<BeanFactoryPostProcessor>)属性
         * 这个方法可以在这个list中直接添加BeanFactoryPostProcessor
         */
        ac.addBeanFactoryPostProcessor(new AddByApplicationContextBeanFactoryPostProcessor());
        ac.addBeanFactoryPostProcessor(new AddByApplicationContextBeanDefinitionRegistryPostProcessor());
        ac.register(TestBeanFactoryPostProcessorMain.class);
        ac.refresh();
    }
}
